package com.kis.controller.index;

import com.kis.service.group.GroupService;
import com.kis.service.user.ShiqiUserService;
import com.kis.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * Created by wongloong on 16-4-14.
 */
@Controller
public class IndexController {
    @Autowired
    UserService userService;
    @Autowired
    Environment env;
    @Autowired
    GroupService groupService;
    @Autowired
    ShiqiUserService shiqiUserService;

    @RequestMapping("/")
    public String index() {
//        System.out.println(userService.findUserByUserId(100000329L).toString());
        shiqiUserService.test();
        return "index";
    }

    @RequestMapping("/testEmpty")
    public String testEmpty() {
        long startTime = System.currentTimeMillis();
        System.out.println(userService.testEmpty(""));
        long endTime = System.currentTimeMillis();
        System.out.println(endTime - startTime);
        return "index";
    }

    @RequestMapping("/test/1k")
    public String test1k(Model model, HttpSession session) {
        if (null != session.getAttribute("test")) {
            System.out.println(session.getAttribute("test"));
            String s = session.getAttribute("test").toString();
            model.addAttribute(s, s);
            model.addAttribute("sessionId", session.getId());
        } else {
            session.setAttribute("test", "testredis");
        }
//        System.out.println("=====================");
//        System.out.println(env.getProperty("spring.data"));
//        System.out.println("=====================");
        return "index";
    }
}
